
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class 使用List {
    public static void main(String[] args) {
        //test1();
        test2();
    }
    static void test2(){
        // 构造从start到end的序列：
        final int start = 10;
        final int end = 20;
        List<Integer> list = new ArrayList<>();
        for (int i = start; i <= end; i++) {
            list.add(i);
        }
        // 随机删除List中的一个元素:
        int removed = list.remove((int) (Math.random() * list.size()));
        int found = findMissingNumber(start, end, list);
        System.out.println(list.toString());
        System.out.println("missing number: " + found);
        System.out.println(removed == found ? "测试成功" : "测试失败");
    }
    static int findMissingNumber(int start, int end, List<Integer> list) {
        int sum = 0, res = 0;
        for(Integer in:list){
            res ^= in.intValue();
            System.out.println("res:"+res);
        }  
        for(int i = start; i <= end; i ++ ){
            sum ^= i;
            System.out.println("sum:"+sum);
        } 
        return res ^ sum;
    }
    static void test1(){
        List<String> list=new ArrayList<String>();
        list.add("apple");
        list.add("pear");
        list.add(null);
        list.add("apple");
        System.out.println(list.size());
        for(Iterator<String> it=list.iterator();it.hasNext();){
            String s=it.next();
            System.out.println(s);
        }
        for(String s:list){
            System.out.println(s);
        }
    }
}
